home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter5 / 5.33 / 5.33.cs next >
Text File  |  2004-10-30  |  1KB  |  40 lines

  1. /* Public Inheritance with protected members. */
  2. using System;
  3.  
  4. namespace Chapter5 {
  5.     public class BaseClass {
  6.         protected short Width, Length;
  7.  
  8.         public BaseClass() {}
  9.         public BaseClass(short w, short l) {
  10.             Width = w;
  11.             Length = l;
  12.         }
  13.  
  14.         public static void ReadWidth(BaseClass X) {
  15.             Console.WriteLine(X.Width);
  16.         }
  17.  
  18.         public static void ReadLength(BaseClass X) {
  19.             Console.WriteLine(X.Length);
  20.         }
  21.     }
  22.  
  23.     public class DerivedClass : BaseClass {
  24.         DerivedClass(short w, short l) {
  25.             Width = w;
  26.             Length = l;
  27.         }
  28.  
  29.         public static void DisplayArea(DerivedClass Y) { 
  30.             Console.WriteLine("Area = " + Y.Width * Y.Length);
  31.         }
  32.  
  33.         static void Main() {
  34.             DerivedClass Instance = new DerivedClass(5, 6);
  35.             ReadWidth(Instance);
  36.             ReadLength(Instance);
  37.             DisplayArea(Instance);
  38.         }
  39.     }
  40. }